package com.kgc.scd.config;


import com.kgc.scd.interceptor.RequestPermissionInterceptor;
import com.kgc.scd.resolver.RequestUserResolver;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.format.FormatterRegistry;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.validation.MessageCodesResolver;
import org.springframework.validation.Validator;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.method.support.HandlerMethodReturnValueHandler;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.config.annotation.*;


import java.util.List;

/**
 * @program: com.kgc.springcloud.config
 * @author: HarryXzy
 * @create: 2022-06-01 11:09
 * @description:
 **/
@Configuration
public class MyWebMvcConfig implements WebMvcConfigurer {
    
    /**
    * @author: HarryXzy 
    * @date: 2022/6/1 11:11
    * @return: com.kgc.springcloud.interceptor.RequestPermissionInterceptor 
    * @description:
    */
    @Bean
    public RequestPermissionInterceptor requestPermissionInterceptor(){
        return new RequestPermissionInterceptor();
    }

    /**
    * @author: HarryXzy
    * @date: 2022/6/1 11:37
    * @return: com.kgc.springcloud.resolver.RequestUserResolver
    * @description: 请求用户信息解析器到容器中
    */
    @Bean
    public RequestUserResolver requestUserResolver(){
        return new RequestUserResolver();
    }
    
    @Override
    public void configurePathMatch(PathMatchConfigurer pathMatchConfigurer) {

    }

    @Override
    public void configureContentNegotiation(ContentNegotiationConfigurer contentNegotiationConfigurer) {

    }

    @Override
    public void configureAsyncSupport(AsyncSupportConfigurer asyncSupportConfigurer) {

    }

    @Override
    public void configureDefaultServletHandling(DefaultServletHandlerConfigurer defaultServletHandlerConfigurer) {

    }

    @Override
    public void addFormatters(FormatterRegistry formatterRegistry) {

    }

    @Override
    public void addInterceptors(InterceptorRegistry interceptorRegistry) {
        // 手动添加自动移请求许可拦截器
        interceptorRegistry.addInterceptor(requestPermissionInterceptor()).addPathPatterns("/*");
    }


    @Override
    public void addResourceHandlers(ResourceHandlerRegistry resourceHandlerRegistry) {

    }

    @Override
    public void addCorsMappings(CorsRegistry corsRegistry) {

    }

    @Override
    public void addViewControllers(ViewControllerRegistry viewControllerRegistry) {

    }

    @Override
    public void configureViewResolvers(ViewResolverRegistry viewResolverRegistry) {

    }

    @Override
    public void addArgumentResolvers(List<HandlerMethodArgumentResolver> list) {
        // 手动添加自定义请求参数解析器
        list.add(requestUserResolver());
    }

    @Override
    public void addReturnValueHandlers(List<HandlerMethodReturnValueHandler> list) {

    }

    @Override
    public void configureMessageConverters(List<HttpMessageConverter<?>> list) {

    }

    @Override
    public void extendMessageConverters(List<HttpMessageConverter<?>> list) {

    }

    @Override
    public void configureHandlerExceptionResolvers(List<HandlerExceptionResolver> list) {

    }

    @Override
    public void extendHandlerExceptionResolvers(List<HandlerExceptionResolver> list) {

    }

    @Override
    public Validator getValidator() {
        return null;
    }

    @Override
    public MessageCodesResolver getMessageCodesResolver() {
        return null;
    }
}
